define([], function() {
    return {
        appStaffInit: function(_appStaff) {
            appStaffObj = {
                staff_id: 0,
                relations: [],
                old_relations: [],
                search: function(obj) {
                    var param = {};
                    $.each($("#fm-app-staff").serializeArray(), function(k, v) {
                        var key = $.trim(v.name);
                        var value = $.trim(v.value);
                        param[key] = value;
                    });
                    $('#appStaffTable').datagrid('load', param);
                },
                reset: function(obj) {
                    $('#fm-app-staff').form('reset');
                },
                add: function(obj) {
                    $('#dlg-app-staff-edit').dialog('close');
                    $('#fm-app-staff-add').form('clear');
                    $('#dlg-app-staff-add').dialog('open').dialog('center').dialog('setTitle', '新增用户');
                },
                relationApp: function(obj) {
                    $('#dlg-app-staff-edit').dialog('close');
                    $('#dlg-app-staff-add').dialog('close');
                    $('#dlg-app-staff-app-relation').dialog({
                        onOpen: function() {
                            var body = $(this).panel('body');
                            var json = $(obj).attr('data');
                            var staff = $.parseJSON(json);
                            //
                            appStaffObj.relations = [];
                            appStaffObj.old_relations = [];
                            appStaffObj.staff_id = staff['id'];
                            //获取用户关联apps以及App关联角色组
                            var staff_apps_url = _appStaff.get_staff_apps;
                            var apps = commonObj.toGetData(staff_apps_url, {
                                'staff_id': staff['id']
                            });
                            //
                            body.find("input[type='checkbox']").prop("checked", false);
                            body.find("input[type='radio']").removeAttr("checked");
                            body.find("input[type='radio']").attr("disabled", "disabled");
                            $.each(apps.data, function(k, v) {
                                if (v['status'] == 1) {
                                    //
                                    body.find('#app_id_' + v['app_id']).prop("checked", true);
                                    body.find('#app_group_id_' + v['group_id']).prop("checked", "checked");
                                    body.find('input[name="group_id_' + v['app_id'] + '"]').removeAttr("disabled");
                                    //
                                    relation = {
                                        'app_id': v['app_id'],
                                        'group_id': v['group_id']
                                    };
                                    appStaffObj.relations[v['app_id']] = relation;
                                    appStaffObj.old_relations[v['app_id']] = relation;
                                }
                            });
                            //获取用户关联app的角色组
                        }
                    });
                    $('#dlg-app-staff-app-relation').dialog('open').dialog('center').dialog('setTitle', '用户关联应用');
                },
                changeApp: function(obj) {
                    var ischecked = $(obj).prop("checked");
                    var groupObj = $(obj).parent().parent().find('td ul li input[type="radio"]');
                    var app_id = $(obj).val();
                    var select_group_id = appStaffObj.old_relations[app_id] == undefined ? 0 : appStaffObj.old_relations[app_id]['group_id'];
                    //
                    if (ischecked) {
                        //
                        groupObj.removeAttr("disabled");
                        //
                        $(obj).parent().parent().find('td ul li input#app_group_id_' + select_group_id).prop("checked", "checked");
                        //
                        var group_id = groupObj.filter(':checked').val();
                        var relation = {
                            'app_id': app_id,
                            'group_id': group_id
                        };
                        appStaffObj.relations[app_id] = relation;
                    } else {
                        //
                        groupObj.removeAttr("checked");
                        groupObj.attr("disabled", "disabled");
                        appStaffObj.relations[app_id] = null;
                    }
                },
                changeAuthGroup: function(obj) {
                    var app_id = $(obj).attr('data');
                    var group_id = $(obj).val();
                    var relation = {
                        'app_id': app_id,
                        'group_id': group_id
                    };
                    appStaffObj.relations[app_id] = relation;
                },
                relationGroup: function(obj) {
                    //alert('relationGroup')
                },
                edit: function(obj) {
                    //初始化数据
                    var json = $(obj).attr('data');
                    var appStaff = $.parseJSON(json);
                    var title = '编辑用户(' + appStaff.name + ')';
                    $('#fm-app-staff-edit').form('clear');
                    $('#dlg-app-staff-add').dialog('close');
                    //
                    $("#app-staff-edit-dept_id").combobox('select', appStaff['dept_id']);
                    $("#app-staff-edit-post_id").combobox('select', appStaff['post_id']);
                    $('#dlg-app-staff-edit').dialog({
                        onOpen: function() {
                            var body = $(this).panel('body');
                            $.each(appStaff, function(k, v) {
                                if ($.inArray(k, ['dept_id', 'post_id']) == -1) {
                                    body.find('#app-staff-edit-' + k).textbox({
                                        value: v
                                    }).attr("placeholder", $(this).attr("placeholder"));
                                }
                            });
                        }
                    });
                    //
                    $('#dlg-app-staff-edit').dialog('open').dialog('center').dialog('setTitle', title);
                },
                save: function(obj) {
                    var url = _appStaff.get_add_url;
                    $('#fm-app-staff-add').form('submit', {
                        url: url,
                        onSubmit: function(param) {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $.messager.progress('close');
                            }
                            return isValid;
                        },
                        success: function(json) {
                            var _data = $.parseJSON(json);
                            if (_data['status']) {
                                $.messager.alert('error', _data['msg'], 'error');
                                return false;
                            }
                            $('#dlg-app-staff-add').dialog('close');
                            $("#appStaffTable").datagrid('reload');
                        }
                    });
                },
                modify: function(obj) {
                    var url = _appStaff.get_edit_url;
                    $('#fm-app-staff-edit').form('submit', {
                        url: url,
                        onSubmit: function(param) {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $.messager.progress('close');
                            }
                            return isValid;
                        },
                        success: function(json) {
                            var _data = $.parseJSON(json);
                            if (_data['status']) {
                                $.messager.alert('error', _data['msg'], 'error');
                                return false;
                            }
                            $('#dlg-app-staff-edit').dialog('close');
                            $("#appStaffTable").datagrid('reload');
                        }
                    });
                },
                modifyStaffAppRelation: function(obj) {
                    var url = _appStaff.get_edit_staff_app_relation_url;
                    var data = {
                        'staff_id': this.staff_id,
                        'relations': this.relations
                    };
                    $.ajax({
                        url: url,
                        data: data,
                        success: function(json) {
                            if (json['status']) {
                                $.messager.alert('error', json['msg'], 'error');
                                return false;
                            }
                            appStaffObj.cancel();
                        }
                    });
                },
                // detail: function(obj) {
                //     $.messager.alert('用户详情', '尚无详情！', 'info');
                // },
                disable: function(obj) {
                    var json = $(obj).attr('data');
                    var staff = $.parseJSON(json);
                    $.messager.confirm('提示', '确定要隐藏用户-<' + staff['name'] + '>', function(r) {
                        if (r) {
                            var url = _appStaff.get_edit_url;
                            var data = {
                                'id': staff['id'],
                                'dept_id': staff['dept_id'],
                                'post_id': staff['post_id'],
                                'name': staff['name'],
                                'account': staff['account'],
                                'mobile': staff['mobile'],
                                'email': staff['email'],
                                'status': '0',
                            };
                            //
                            $.ajax({
                                url: url,
                                data: data,
                                success: function(json) {
                                    if (json['status']) {
                                        $.messager.alert('error', json['msg'], 'error');
                                        return false;
                                    }
                                    appStaffObj.cancel();
                                }
                            });
                        }
                    });
                },
                enable: function(obj) {
                    var json = $(obj).attr('data');
                    var staff = $.parseJSON(json);
                    $.messager.confirm('提示', '确定要启用用户-<' + staff['name'] + '>', function(r) {
                        if (r) {
                            var url = _appStaff.get_edit_url;
                            var data = {
                                'id': staff['id'],
                                'dept_id': staff['dept_id'],
                                'post_id': staff['post_id'],
                                'name': staff['name'],
                                'account': staff['account'],
                                'mobile': staff['mobile'],
                                'email': staff['email'],
                                'status': '1',
                            };
                            //
                            $.ajax({
                                url: url,
                                data: data,
                                success: function(json) {
                                    if (json['status']) {
                                        $.messager.alert('error', json['msg'], 'error');
                                        return false;
                                    }
                                    $("#appStaffTable").datagrid('reload');
                                }
                            });
                        }
                    });
                },
                resetPwd: function(obj) {
                    var json = $(obj).attr('data');
                    var staff = $.parseJSON(json);
                    $.messager.confirm('提示', '确定要重置' + staff['name'] + '的密码？', function(r) {
                        if (r) {
                            var url = _appStaff.get_edit_url;
                            var data = {
                                'type': 'resetPwd',
                                'id': staff['id'],
                                'dept_id': staff['dept_id'],
                                'post_id': staff['post_id'],
                                'name': staff['name'],
                                'account': staff['account'],
                                'mobile': staff['mobile'],
                                'email': staff['email'],
                                'password': 123321,
                                'status': staff['status'],
                            };
                            //
                            $.ajax({
                                url: url,
                                data: data,
                                success: function(json) {
                                    if (json['status']) {
                                        $.messager.alert('error', json['msg'], 'error');
                                        return false;
                                    }
                                    $.messager.alert('重置结果', "重置后密码为123321", 'info');
                                    $("#appStaffTable").datagrid('reload');
                                }
                            });
                        }
                    });
                },
                cancel: function(obj) {
                    $('#dlg-app-staff-add').dialog('close');
                    $('#dlg-app-staff-edit').dialog('close');
                    $('#dlg-app-staff-app-relation').dialog('close');
                }
            };
            var queryParams = {};
            $.each($("#fm-app-staff").serializeArray(), function(k, v) {
                var key = $.trim(v.name);
                var value = $.trim(v.value);
                queryParams[key] = value;
            });
            //
            var deptJson = _appStaff.get_dept_json;
            var deptArr = $.parseJSON(deptJson);
            var postJson = _appStaff.get_post_json;
            var postArr = $.parseJSON(postJson);
            $("#appStaffTable").datagrid({
                url: _appStaff.get_list_url,
                method: 'GET',
                queryParams: queryParams,
                striped: false,
                fit: true,
                border: false,
                fitColumns: true,
                singleSelect: true,
                stripedrd: true,
                rownumbers: true,
                pagination: true,
                idField: 'id',
                nowrap: false,
                pageSize: 35,
                pageList: [35, 40, 50, 100],
                showFooter: true,
                sortName: 'id',
                sortOrder: 'ASC',
                remoteSort: true,
                scrollbarSize: 0,
                columns: [
                    [{
                        field: 'id',
                        checkbox: true,
                    }, {
                        field: 'name',
                        title: '名称',
                        width: '10%',
                        align: 'left'
                    }, {
                        field: 'account',
                        title: '账号',
                        width: '10%',
                        align: 'left'
                    }, {
                        field: 'mobile',
                        title: '手机',
                        width: '10%',
                        align: 'left',
                        sortable: false
                    }, {
                        field: 'dept_id',
                        title: '部门',
                        width: '12%',
                        align: 'left',
                        sortable: false,
                        formatter: function(value, data, index) {
                            return deptArr[value];
                        }
                    }, {
                        field: 'post_id',
                        title: '职称',
                        width: '8%',
                        align: 'left',
                        sortable: false,
                        formatter: function(value, data, index) {
                            return postArr[value];
                        }
                    }, {
                        field: 'operator_name',
                        title: '添加人',
                        width: '5%',
                        align: 'center'
                    }, {
                        field: 'created_at',
                        title: '添加时间',
                        width: '10%',
                        align: 'center',
                        sortable: true
                    }, {
                        field: 'updated_at',
                        title: '关联',
                        width: '8%',
                        align: 'center',
                        sortable: false,
                        formatter: function(value, data, index) {
                            var str = '';
                            var json = JSON.stringify(data);
                            str += "<a class='loan_staff_app_relation_button' data='" + json + "' onclick='appStaffObj.relationApp(this);'></a>";
                            //str += "<a class='loan_staff_group_relation_button' data='" + json + "' onclick='appStaffObj.relationGroup(this);'></a>";
                            return str;
                        }
                    }, {
                        field: 'status',
                        title: '状态',
                        width: '5%',
                        align: 'center',
                        sortable: true,
                        formatter: function(value, data, index) {
                            var str = '';
                            if (value == 1) str = '<a style="background:#5cb85c;display:block;color:white;">正常</a>';
                            if (value == 0) str = '<a style="background:#f0ad4e;display:block;color:white;">隐藏</a>';
                            if (value == 3) str = '<a style="background:#d9534f;display:block;color:white;">软删</a>';
                            return str;
                        }
                    }, {
                        field: 'deleted_at',
                        title: '操作',
                        width: '20%',
                        align: 'center',
                        sortable: false,
                        formatter: function(value, data, index) {
                            var str = '';
                            var json = JSON.stringify(data);
                            str += "<a class='loan_app_staff_edit_button' data='" + json + "' onclick='appStaffObj.edit(this);'></a>";
                            // str += "<a class='loan_app_staff_detail_button' data='" + json + "' onclick='appStaffObj.detail(this);'></a>";
                            //
                            if (data['status'] == 0) {
                                str += "<a data='" + json + "' onClick='appStaffObj.enable(this);' class='loan_app_staff_enable_button'></a>";
                            } else {
                                str += "<a data='" + json + "' onClick='appStaffObj.disable(this);' class='loan_app_staff_disable_button'></a>";
                            }
                            str += "<a class='loan_app_staff_retset_pwd_button' data='" + json + "' onclick='appStaffObj.resetPwd(this);'></a>";
                            return str;
                        }
                    }]
                ],
                toolbar: '#appStaffToolBar',
                onBeforeLoad: function(param) {},
                onLoadSuccess: function(data) {
                    //关系
                    $(".loan_staff_app_relation_button").linkbutton({
                        text: '应用',
                        plain: true,
                        iconCls: 'icon-application_link'
                    });
                    // $(".loan_staff_group_relation_button").linkbutton({
                    //     text: '分组',
                    //     plain: true,
                    //     iconCls: 'icon-group_link'
                    // });
                    //操作
                    $(".loan_app_staff_edit_button").linkbutton({
                        text: '编辑',
                        plain: true,
                        iconCls: 'icon-user_edit'
                    });
                    // $(".loan_app_staff_detail_button").linkbutton({
                    //     text: '详情',
                    //     plain: true,
                    //     iconCls: 'icon-user_star'
                    // });
                    $(".loan_app_staff_disable_button").linkbutton({
                        text: '禁用',
                        plain: true,
                        iconCls: 'icon-user_cross'
                    });
                    $(".loan_app_staff_enable_button").linkbutton({
                        text: '启用',
                        plain: true,
                        iconCls: 'icon-user_tick'
                    });
                    $(".loan_app_staff_retset_pwd_button").linkbutton({
                        text: '重置',
                        plain: true,
                        iconCls: 'icon-key'
                    });
                    $('#appStaffTable').datagrid('fixRowHeight');
                },
                onLoadError: function() {},
                onClickCell: function(rowIndex, field, value) {},
                onDblClickRow: function(rowIndex, rowData) {},
                onAfterEdit: function(rowIndex, rowData, changes) {}
            });
        },
        appStaffDeptInit: function(_appStaffDept) {
            appStaffDeptObj = {
                search: function(obj) {
                    var param = {};
                    $.each($("#fm-app-staff-dept").serializeArray(), function(k, v) {
                        var key = $.trim(v.name);
                        var value = $.trim(v.value);
                        param[key] = value;
                    });
                    $('#appStaffDeptTable').datagrid('load', param);
                },
                reset: function(obj) {
                    $('#fm-app-staff-dept').form('reset');
                },
                add: function(obj) {
                    $('#dlg-app-staff-dept-edit').dialog('close');
                    $('#fm-app-staff-dept-add').form('clear');
                    $('#dlg-app-staff-dept-add').dialog('open').dialog('center').dialog('setTitle', '新增部门');
                },
                relationApp: function(obj) {
                    alert('relationApp')
                },
                relationGroup: function(obj) {
                    alert('relationGroup')
                },
                edit: function(obj) {
                    //初始化数据
                    var json = $(obj).attr('data');
                    var appStaff = $.parseJSON(json);
                    console.log(appStaff);
                    var title = '编辑用户(' + appStaff.name + ')';
                    $('#fm-app-staff-dept-edit').form('clear');
                    $('#dlg-app-staff-dept-add').dialog('close');
                    //
                    $('#dlg-app-staff-dept-edit').dialog({
                        onOpen: function() {
                            var body = $(this).panel('body');
                            $.each(appStaff, function(k, v) {
                                if (k != 'app_id') {
                                    body.find('#app-staff-dept-edit-' + k).textbox({
                                        value: v
                                    }).attr("placeholder", $(this).attr("placeholder"));
                                }
                            });
                        }
                    });
                    //
                    $('#dlg-app-staff-dept-edit').dialog('open').dialog('center').dialog('setTitle', title);
                },
                save: function(obj) {
                    var url = _appStaffDept.get_add_url;
                    $('#fm-app-staff-dept-add').form('submit', {
                        url: url,
                        onSubmit: function(param) {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $.messager.progress('close');
                            }
                            return isValid;
                        },
                        success: function(json) {
                            var _data = $.parseJSON(json);
                            if (_data['status']) {
                                $.messager.alert('error', _data['msg'], 'error');
                                return false;
                            }
                            $('#dlg-app-staff-dept-add').dialog('close');
                            $("#appStaffDeptTable").datagrid('reload');
                        }
                    });
                },
                modify: function(obj) {
                    var url = _appStaffDept.get_edit_url;
                    $('#fm-app-staff-dept-edit').form('submit', {
                        url: url,
                        onSubmit: function(param) {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $.messager.progress('close');
                            }
                            return isValid;
                        },
                        success: function(json) {
                            var _data = $.parseJSON(json);
                            if (_data['status']) {
                                $.messager.alert('error', _data['msg'], 'error');
                                return false;
                            }
                            $('#dlg-app-staff-dept-edit').dialog('close');
                            $("#appStaffDeptTable").datagrid('reload');
                        }
                    });
                },
                detail: function(obj) {
                    $.messager.alert('用户详情', '尚无详情！', 'info');
                },
                disable: function(obj) {
                    var json = $(obj).attr('data');
                    var dept = $.parseJSON(json);
                    $.messager.confirm('提示', '确定要隐藏部门-<' + dept['name'] + '>', function(r) {
                        if (r) {
                            var url = _appStaffDept.get_edit_url;
                            var data = {
                                'id': dept['id'],
                                'name': dept['name'],
                                'telephone': dept['telephone'],
                                'leader': dept['leader'],
                                'desc': dept['desc'],
                                'status': '0',
                            };
                            //
                            $.ajax({
                                url: url,
                                data: data,
                                success: function(json) {
                                    if (json['status']) {
                                        $.messager.alert('error', json['msg'], 'error');
                                        return false;
                                    }
                                    $("#appStaffDeptTable").datagrid('reload');
                                }
                            });
                        }
                    });
                },
                enable: function(obj) {
                    var json = $(obj).attr('data');
                    var dept = $.parseJSON(json);
                    $.messager.confirm('提示', '确定要启用部门-<' + dept['name'] + '>', function(r) {
                        if (r) {
                            var url = _appStaffDept.get_edit_url;
                            var data = {
                                'id': dept['id'],
                                'name': dept['name'],
                                'telephone': dept['telephone'],
                                'leader': dept['leader'],
                                'desc': dept['desc'],
                                'status': '1',
                            };
                            //
                            $.ajax({
                                url: url,
                                data: data,
                                success: function(json) {
                                    if (json['status']) {
                                        $.messager.alert('error', json['msg'], 'error');
                                        return false;
                                    }
                                    $("#appStaffDeptTable").datagrid('reload');
                                }
                            });
                        }
                    });
                },
                cancel: function(obj) {
                    $('#dlg-app-staff-dept-add').dialog('close');
                    $('#dlg-app-staff-dept-edit').dialog('close');
                }
            };
            var queryParams = {};
            $.each($("#fm-app-staff-dept").serializeArray(), function(k, v) {
                var key = $.trim(v.name);
                var value = $.trim(v.value);
                queryParams[key] = value;
            });
            //
            $("#appStaffDeptTable").datagrid({
                url: _appStaffDept.get_list_url,
                method: 'GET',
                queryParams: queryParams,
                striped: false,
                fit: true,
                border: false,
                fitColumns: true,
                singleSelect: true,
                stripedrd: true,
                rownumbers: true,
                pagination: true,
                idField: 'id',
                nowrap: false,
                pageSize: 35,
                pageList: [35, 40, 50, 100],
                showFooter: true,
                sortName: 'id',
                sortOrder: 'ASC',
                remoteSort: true,
                scrollbarSize: 0,
                columns: [
                    [{
                        field: 'id',
                        checkbox: true,
                    }, {
                        field: 'name',
                        title: '名称',
                        width: '10%',
                        align: 'left'
                    }, {
                        field: 'telephone',
                        title: '电话',
                        width: '10%',
                        align: 'left'
                    }, {
                        field: 'leader',
                        title: '部门负责人',
                        width: '10%',
                        align: 'left',
                        sortable: false
                    }, {
                        field: 'desc',
                        title: '介绍',
                        width: '15%',
                        align: 'left',
                        sortable: false
                    }, {
                        field: 'operator_name',
                        title: '添加人',
                        width: '5%',
                        align: 'center'
                    }, {
                        field: 'created_at',
                        title: '添加时间',
                        width: '10%',
                        align: 'center',
                        sortable: true
                    }, {
                        field: 'updated_at',
                        title: '配置',
                        width: '13%',
                        align: 'center',
                        sortable: false,
                        formatter: function(value, data, index) {
                            var str = '';
                            var json = JSON.stringify(data);
                            str += "<a class='loan_app_staff_dept_relation_data_button' data='" + json + "' onclick='appStaffDeptObj.relationApp(this);'></a>";
                            return str;
                        }
                    }, {
                        field: 'status',
                        title: '状态',
                        width: '5%',
                        align: 'center',
                        sortable: true,
                        formatter: function(value, data, index) {
                            var str = '';
                            if (value == 1) str = '<a style="background:#5cb85c;display:block;color:white;">正常</a>';
                            if (value == 0) str = '<a style="background:#f0ad4e;display:block;color:white;">隐藏</a>';
                            if (value == 3) str = '<a style="background:#d9534f;display:block;color:white;">软删</a>';
                            return str;
                        }
                    }, {
                        field: 'deleted_at',
                        title: '操作',
                        width: '20%',
                        align: 'center',
                        sortable: false,
                        formatter: function(value, data, index) {
                            var str = '';
                            var json = JSON.stringify(data);
                            str += "<a class='loan_app_staff_dept_edit_button' data='" + json + "' onclick='appStaffDeptObj.edit(this);'></a>";
                            //
                            if (data['status'] == 0) {
                                str += "<a data='" + json + "' onClick='appStaffDeptObj.enable(this);' class='loan_app_staff_dept_enable_button'></a>";
                            } else {
                                str += "<a data='" + json + "' onClick='appStaffDeptObj.disable(this);' class='loan_app_staff_dept_disable_button'></a>";
                            }
                            return str;
                        }
                    }]
                ],
                toolbar: '#appStaffDeptToolBar',
                onBeforeLoad: function(param) {},
                onLoadSuccess: function(data) {
                    //配置
                    $(".loan_app_staff_dept_relation_data_button").linkbutton({
                        text: '额外参数',
                        plain: true,
                        iconCls: 'icon-page_white_edit'
                    });
                    //操作
                    $(".loan_app_staff_dept_edit_button").linkbutton({
                        text: '编辑',
                        plain: true,
                        iconCls: 'icon-user_edit'
                    });
                    $(".loan_app_staff_dept_disable_button").linkbutton({
                        text: '禁用',
                        plain: true,
                        iconCls: 'icon-user_cross'
                    });
                    $(".loan_app_staff_dept_enable_button").linkbutton({
                        text: '启用',
                        plain: true,
                        iconCls: 'icon-user_tick'
                    });
                    $('#appStaffDeptTable').datagrid('fixRowHeight');
                },
                onLoadError: function() {},
                onClickCell: function(rowIndex, field, value) {},
                onDblClickRow: function(rowIndex, rowData) {},
                onAfterEdit: function(rowIndex, rowData, changes) {}
            });
        },
        appStaffPostInit: function(_appStaffPost) {
            appStaffPostObj = {
                search: function(obj) {
                    var param = {};
                    $.each($("#fm-app-staff-post").serializeArray(), function(k, v) {
                        var key = $.trim(v.name);
                        var value = $.trim(v.value);
                        param[key] = value;
                    });
                    $('#appStaffPostTable').datagrid('load', param);
                },
                reset: function(obj) {
                    $('#fm-app-staff-post').form('reset');
                },
                add: function(obj) {
                    $('#dlg-app-staff-post-edit').dialog('close');
                    $('#fm-app-staff-post-add').form('clear');
                    $('#dlg-app-staff-post-add').dialog('open').dialog('center').dialog('setTitle', '新增职称');
                },
                relationApp: function(obj) {
                    alert('relationApp')
                },
                relationGroup: function(obj) {
                    alert('relationGroup')
                },
                edit: function(obj) {
                    //初始化数据
                    var json = $(obj).attr('data');
                    var appStaffPost = $.parseJSON(json);
                    console.log(appStaffPost);
                    var title = '编辑职称(' + appStaffPost.name + ')';
                    $('#fm-app-staff-post-edit').form('clear');
                    $('#dlg-app-staff-post-add').dialog('close');
                    //
                    $('#dlg-app-staff-post-edit').dialog({
                        onOpen: function() {
                            var body = $(this).panel('body');
                            $.each(appStaffPost, function(k, v) {
                                if (k != 'app_id') {
                                    body.find('#app-staff-post-edit-' + k).textbox({
                                        value: v
                                    }).attr("placeholder", $(this).attr("placeholder"));
                                }
                            });
                        }
                    });
                    //
                    $('#dlg-app-staff-post-edit').dialog('open').dialog('center').dialog('setTitle', title);
                },
                save: function(obj) {
                    var url = _appStaffPost.get_add_url;
                    $('#fm-app-staff-post-add').form('submit', {
                        url: url,
                        onSubmit: function(param) {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $.messager.progress('close');
                            }
                            return isValid;
                        },
                        success: function(json) {
                            var _data = $.parseJSON(json);
                            if (_data['status']) {
                                $.messager.alert('error', _data['msg'], 'error');
                                return false;
                            }
                            $('#dlg-app-staff-post-add').dialog('close');
                            $("#appStaffPostTable").datagrid('reload');
                        }
                    });
                },
                modify: function(obj) {
                    var url = _appStaffPost.get_edit_url;
                    $('#fm-app-staff-post-edit').form('submit', {
                        url: url,
                        onSubmit: function(param) {
                            var isValid = $(this).form('validate');
                            if (!isValid) {
                                $.messager.progress('close');
                            }
                            return isValid;
                        },
                        success: function(json) {
                            var _data = $.parseJSON(json);
                            if (_data['status']) {
                                $.messager.alert('error', _data['msg'], 'error');
                                return false;
                            }
                            $('#dlg-app-staff-post-edit').dialog('close');
                            $("#appStaffPostTable").datagrid('reload');
                        }
                    });
                },
                detail: function(obj) {
                    $.messager.alert('用户详情', '尚无详情！', 'info');
                },
                disable: function(obj) {
                    var json = $(obj).attr('data');
                    var post = $.parseJSON(json);
                    $.messager.confirm('提示', '确定要隐藏职称-<' + post['name'] + '>', function(r) {
                        if (r) {
                            var url = _appStaffPost.get_edit_url;
                            var data = {
                                'id': post['id'],
                                'name': post['name'],
                                'code': post['code'],
                                'desc': post['desc'],
                                'status': '0',
                            };
                            //
                            $.ajax({
                                url: url,
                                data: data,
                                success: function(json) {
                                    if (json['status']) {
                                        $.messager.alert('error', json['msg'], 'error');
                                        return false;
                                    }
                                    $("#appStaffPostTable").datagrid('reload');
                                }
                            });
                        }
                    });
                },
                enable: function(obj) {
                    var json = $(obj).attr('data');
                    var post = $.parseJSON(json);
                    $.messager.confirm('提示', '确定要启用职称-<' + post['name'] + '>', function(r) {
                        if (r) {
                            var url = _appStaffPost.get_edit_url;
                            var data = {
                                'id': post['id'],
                                'name': post['name'],
                                'code': post['code'],
                                'desc': post['desc'],
                                'status': '1',
                            };
                            //
                            $.ajax({
                                url: url,
                                data: data,
                                success: function(json) {
                                    if (json['status']) {
                                        $.messager.alert('error', json['msg'], 'error');
                                        return false;
                                    }
                                    $("#appStaffPostTable").datagrid('reload');
                                }
                            });
                        }
                    });
                },
                cancel: function(obj) {
                    $('#dlg-app-staff-post-add').dialog('close');
                    $('#dlg-app-staff-post-edit').dialog('close');
                }
            };
            var queryParams = {};
            $.each($("#fm-app-staff-post").serializeArray(), function(k, v) {
                var key = $.trim(v.name);
                var value = $.trim(v.value);
                queryParams[key] = value;
            });
            //
            $("#appStaffPostTable").datagrid({
                url: _appStaffPost.get_list_url,
                method: 'GET',
                queryParams: queryParams,
                striped: false,
                fit: true,
                border: false,
                fitColumns: true,
                singleSelect: true,
                stripedrd: true,
                rownumbers: true,
                pagination: true,
                idField: 'id',
                nowrap: false,
                pageSize: 35,
                pageList: [35, 40, 50, 100],
                showFooter: true,
                sortName: 'id',
                sortOrder: 'ASC',
                remoteSort: true,
                scrollbarSize: 0,
                columns: [
                    [{
                        field: 'id',
                        checkbox: true,
                    }, {
                        field: 'name',
                        title: '名称',
                        width: '10%',
                        align: 'left'
                    }, {
                        field: 'code',
                        title: '编码',
                        width: '10%',
                        align: 'left'
                    }, {
                        field: 'desc',
                        title: '介绍',
                        width: '25%',
                        align: 'left',
                        sortable: false
                    }, {
                        field: 'operator_name',
                        title: '添加人',
                        width: '5%',
                        align: 'center'
                    }, {
                        field: 'created_at',
                        title: '添加时间',
                        width: '10%',
                        align: 'center',
                        sortable: true
                    }, {
                        field: 'updated_at',
                        title: '配置',
                        width: '13%',
                        align: 'center',
                        sortable: false,
                        formatter: function(value, data, index) {
                            var str = '';
                            var json = JSON.stringify(data);
                            str += "<a class='loan_app_staff_dept_relation_data_button' data='" + json + "' onclick='appStaffPostObj.relationApp(this);'></a>";
                            return str;
                        }
                    }, {
                        field: 'status',
                        title: '状态',
                        width: '5%',
                        align: 'center',
                        sortable: true,
                        formatter: function(value, data, index) {
                            var str = '';
                            if (value == 1) str = '<a style="background:#5cb85c;display:block;color:white;">正常</a>';
                            if (value == 0) str = '<a style="background:#f0ad4e;display:block;color:white;">隐藏</a>';
                            if (value == 3) str = '<a style="background:#d9534f;display:block;color:white;">软删</a>';
                            return str;
                        }
                    }, {
                        field: 'deleted_at',
                        title: '操作',
                        width: '20%',
                        align: 'center',
                        sortable: false,
                        formatter: function(value, data, index) {
                            var str = '';
                            var json = JSON.stringify(data);
                            str += "<a class='loan_app_staff_post_edit_button' data='" + json + "' onclick='appStaffPostObj.edit(this);'></a>";
                            //
                            if (data['status'] == 0) {
                                str += "<a data='" + json + "' onClick='appStaffPostObj.enable(this);' class='loan_app_staff_post_enable_button'></a>";
                            } else {
                                str += "<a data='" + json + "' onClick='appStaffPostObj.disable(this);' class='loan_app_staff_post_disable_button'></a>";
                            }
                            return str;
                        }
                    }]
                ],
                toolbar: '#appStaffPostToolBar',
                onBeforeLoad: function(param) {},
                onLoadSuccess: function(data) {
                    //配置
                    $(".loan_app_staff_post_relation_data_button").linkbutton({
                        text: '额外参数',
                        plain: true,
                        iconCls: 'icon-page_white_edit'
                    });
                    //操作
                    $(".loan_app_staff_post_edit_button").linkbutton({
                        text: '编辑',
                        plain: true,
                        iconCls: 'icon-user_edit'
                    });
                    $(".loan_app_staff_post_disable_button").linkbutton({
                        text: '禁用',
                        plain: true,
                        iconCls: 'icon-user_cross'
                    });
                    $(".loan_app_staff_post_enable_button").linkbutton({
                        text: '启用',
                        plain: true,
                        iconCls: 'icon-user_tick'
                    });
                    $('#appStaffPostTable').datagrid('fixRowHeight');
                },
                onLoadError: function() {},
                onClickCell: function(rowIndex, field, value) {},
                onDblClickRow: function(rowIndex, rowData) {},
                onAfterEdit: function(rowIndex, rowData, changes) {}
            });
        }
    }
});